#include <iostream>
#include <vector>
#include <map>
using namespace std;

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int len = INT_MAX;
        int fast = 0;
        int slow = 0;
        int sum = 0;
        int n = nums.size();
        for (; fast < n; fast++)
        {
            sum += nums[fast];
            while (sum >= target)
            {
                if (len > fast - slow + 1)
                {
                    len = fast - slow + 1;
                }
                sum -= nums[slow++];
            }
        }
        return len == INT_MAX ? 0 : len;
    }
};

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int arr[255] = { 0 };
        int fast = 0;
        int slow = 0;
        int n = s.size();
        int len = 0;
        while (fast < n)
        {
            arr[s[fast]]++;
            while (arr[s[fast]] > 1)
            {
                arr[s[slow]]--;
                slow++;
            }
            if (len < fast - slow + 1)
            {
                len = fast - slow + 1;
            }
            fast++;
        }
        return len;
    }
};

class Solution {
public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
        int fast = 0;
        int slow = 0;
        int len = 0;
        int n = nums.size();
        while (fast < n)
        {
            fast++;
            if (nums[fast] == 0)
            {
                slow = fast;
            }
            if (len < fast - slow)
            {
                len = fast - slow;
            }
        }
        return len;
    }
};

class Solution {
public:
    int longestOnes(vector<int>& nums, int k)
    {
        int zero = 0;
        int fast = 0;
        int slow = 0;
        int len = 0;
        int n = nums.size();
        while (fast < n)
        {
            if (nums[fast] == 0)
            {
                zero++;
                while (zero > k)
                {
                    if (nums[slow] == 0)
                    {
                        zero--;
                    }
                    slow++;
                }
            }
            fast++;
            if (len < fast - slow)
            {
                len = fast - slow;
            }
        }
        return len;
    }
};

class Solution {
public:
    int minOperations(vector<int>& nums, int x) {
        int left = 0;
        int right = 0;
        int sum = 0;
        int n = nums.size();
        for (int i = 0; i < n; i++)
        {
            sum += nums[i];
        }
        sum -= x;
        if (sum < 0)
        {
            return -1;
        }
        int len = INT_MAX;
        int sum2 = 0;
        while (right < n)
        {
            sum2 += nums[right];
            while (sum2 > sum)
            {
                sum2 -= nums[left];
                left++;
            }
            if (sum2 == sum)
            {
                if (len > n - (right - left + 1))
                {
                    len = n - (right - left + 1);
                }
            }
            right++;
        }
        return len == INT_MAX ? -1 : len;
    }
};

int main()
{
    map<int, int> m;
    m.insert(pair<int, int>(1, 1));
    return 0;
}